Skip to content

Conversation

@joshheald
Copy link
Contributor

@joshheald joshheald commented Nov 20, 2025

Part of: WOOMOB-1112

Description

Adds analytics tracking for local catalog search performance. This tracks search result fetch times to measure performance of the local GRDB queries.

Changes include:

  • Added pointOfSaleSearchResultsFetched analytics event (renamed from pointOfSaleSearchLocalResultsFetched to reflect that this will be the only search method in the future)
  • Implemented trackSearchLocalResultsFetchComplete in POSItemFetchAnalytics to track fetch duration in milliseconds
  • Integrated timing tracking into local search strategy's fetchProducts method
  • Updated all analytics references across stats, events, and trackers

This PR is stacked on #16375 and is the fourth in a series of 5 PRs implementing local catalog search.

Test Steps

  • Perform a search with local catalog enabled
  • Verify that the search_results_fetched analytics event is fired with correct timing data
  • Check that the event includes item type, results count, and milliseconds since request sent

Note that #16377 resolves all the periphery issues – I'll merge them from that down, so the final merge to trunk will pass periphery. It seems silly to put a load of ignore statements in for the sake of this.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

joshheald and others added 6 commits November 19, 2025 16:23
- Rename analytics event from pointOfSaleSearchLocalResultsFetched to pointOfSaleSearchResultsFetched
- Change stat name from search_local_results_fetched to search_results_fetched
- Add analytics tracking to local search strategy fetchProducts method
- Track milliseconds since request sent and total results count
- Only track on first page to avoid duplicate analytics

The new event name reflects that this will be the only search method
in the future when local catalog is fully rolled out.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Introduces a new enum to define different debouncing behaviors for search operations:

- `.smart(duration)`: Skip debounce on first keystroke after search completes, then debounce subsequent keystrokes. Optimized for slow network searches.
- `.simple(duration, loadingDelayThreshold?)`: Always debounce every keystroke. Optionally delays showing loading indicators until threshold is exceeded. Optimized for fast local searches.
- `.immediate`: No debouncing for non-search operations.

This allows different search types (local vs remote) to use appropriate debouncing strategies tailored to their performance characteristics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds a `debounceStrategy` property to both PointOfSalePurchasableItemFetchStrategy and PointOfSaleCouponFetchStrategy protocols with default implementations returning `.immediate`.

This allows each fetch strategy implementation to declare its optimal debouncing behavior:
- Remote search strategies can use `.smart()` for network latency
- Local search strategies can use `.simple()` with loading delay thresholds
- Default strategies use `.immediate` for no debouncing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements the debouncing strategy pattern in the search UI layer:

- Adds `debounceStrategy` property to POSSearchable protocol
- Updates POSSearchField's onChange handler to execute different debouncing logic based on strategy:
  - `.smart`: Skip debounce on first keystroke, debounce subsequent
  - `.simple`: Always debounce, with optional delayed loading indicators
  - `.immediate`: No debouncing
- Adds `currentDebounceStrategy` to item and coupon controllers to expose fetch strategy's debouncing behavior
- Implements protocol conformance in POSProductSearchable, POSOrderListView, and preview helpers

The `.simple` strategy with loading delay threshold prevents flicker on fast local searches by only showing loading indicators if the search exceeds the threshold duration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Implements `.simple(duration: 150ms, loadingDelayThreshold: 300ms)` for local GRDB product searches.

This strategy:
- Always debounces every keystroke by 150ms to prevent excessive queries
- Delays showing loading indicators until 300ms threshold is exceeded
- Prevents loading flicker for fast local searches (< 300ms)
- Only shows loading indicators for slower searches (> 300ms)

The combination of debouncing with delayed loading provides a responsive feel while avoiding visual flickering on fast local database queries.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Adds comprehensive test coverage for the debouncing strategy pattern:

- Tests for SearchDebounceStrategy enum equality
- Tests verifying each fetch strategy returns the correct debouncing behavior:
  - Local product search: `.simple` with loading delay threshold
  - Remote product search: `.smart` for network latency
  - Coupon search: `.smart` for network latency
  - Default strategies: `.immediate` for no debouncing

Tests ensure the debouncing strategies are correctly configured across all search types for optimal UX.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dangermattic
Copy link
Collaborator

dangermattic commented Nov 20, 2025

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 300 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖

This PR contains changes to Tracks-related logic. Please ensure (author and reviewer) the following are completed:

  • The tracks events must be validated in the Tracks system.
  • Verify the internal Tracks spreadsheet has also been updated.
  • Please consider registering any new events.
  • The PR must be assigned the category: tracks label.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Nov 20, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16376-851119c
Version23.7
Bundle IDcom.automattic.alpha.woocommerce
Commit851119c
Installation URL2v5gtv2r5p7j0
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@joshheald joshheald added type: task An internally driven task. feature: POS labels Nov 20, 2025
@joshheald joshheald added this to the 23.8 milestone Nov 20, 2025
@joshheald joshheald added the category: tracks Related to analytics, including Tracks Events. label Nov 20, 2025
@joshheald joshheald marked this pull request as draft November 20, 2025 11:49
joshheald and others added 15 commits November 20, 2025 11:55
Update mocks to conform to PointOfSaleSearchingItemsControllerProtocol
which now requires currentDebounceStrategy property.
Adds optional loading delay threshold parameter to smart debounce strategy.
This enables delayed loading indicators for fast local searches to prevent
flicker, while maintaining immediate loading indicators for remote searches.

Changes:
- Add optional loadingDelayThreshold parameter to SearchDebounceStrategy.smart case
- Update POSSearchView to handle smart strategy with optional threshold:
  - Check for non-empty search term before showing loading (prevents loading on initial view)
  - Reset didFinishSearch to true when search view appears (ensures first search shows loading)
  - First keystroke without threshold: Show loading immediately (remote searches)
  - First keystroke with threshold: Delay loading until threshold or completion (local searches)
  - Subsequent keystrokes: Debounce request, loading already showing
- Remote searches use .smart without threshold for immediate responsive feedback
- Local searches use .simple with threshold to prevent flicker on fast queries
- Update test expectations to match strategy configurations

Fixes:
- No loading indicators shown when opening search view with popular products
- Loading indicators show immediately on first search keystroke for remote searches
- Local searches avoid flicker by only showing loading if query takes longer than threshold
The issue was that the debounce strategy was determined by the current
fetch strategy, but the fetch strategy didn't change from "popular products"
to "search" until performSearch() was called. This meant the first keystroke
used the `.immediate` strategy from popular products, which set
`didFinishSearch=false` but didn't call `clearSearchResults()` to show loading.

Solution: Added `searchDebounceStrategy` property to POSSearchable protocol
that returns the debounce strategy that will be used for searches, regardless
of the current fetch mode. The onChange handler now captures this strategy
synchronously before creating the Task, ensuring we use the search strategy
(.smart) from the very first keystroke.

Changes:
- Added `searchDebounceStrategy` to POSSearchable protocol
- Updated POSSearchView to use searchDebounceStrategy for non-empty searches
- Implemented searchDebounceStrategy in controllers by creating temporary
  search strategy to query its debounce settings
- Updated all mocks and preview helpers to conform to new protocol

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
The POSSearchable protocol had two confusingly named properties:
- debounceStrategy: The currently active strategy
- searchDebounceStrategy: The strategy that will be used for searches

Renamed debounceStrategy → currentDebounceStrategy to make the
distinction clear: currentDebounceStrategy reflects what's active
right now, while searchDebounceStrategy reflects what will be used
when searching.

This improves code readability without changing any behavior.
@joshheald joshheald marked this pull request as ready for review November 20, 2025 18:38
@iamgabrielma iamgabrielma self-assigned this Nov 24, 2025
Copy link
Contributor

@iamgabrielma iamgabrielma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

🔵 Tracked pos_search_results_fetched, properties: [milliseconds_since_request_sent: 9, plan: jetpack_security_daily, results_count: 6, was_ecommerce_trial: false, site_url: https://indiemelon.mystagingwebsite.com, is_wpcom_store: false, store_id: c5bd46cc-1804-4f7b-badb-bb98c449127f, blog_id: 215063064, source: product]

I fell into the PointOfSaleSearchPurchasableItemFetchStrategy a couple of times, rather than in PointOfSaleLocalSearchPurchasableItemFetchStrategy, logging the event as pos_search_remote_results_fetched instead, but it must have been some Xcode oddness with the project version as I started to get build errors when updating it to 23.8. After clearing the project it was consistent local search

@joshheald joshheald merged commit 5b71a8e into woomob-1112-woo-poslocal-catalog-factory-integration Nov 24, 2025
4 of 13 checks passed
@joshheald joshheald deleted the woomob-1112-woo-poslocal-catalog-analytics branch November 24, 2025 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: tracks Related to analytics, including Tracks Events. feature: POS type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants